package com.cn.ant.modules.wechat.service;

import com.cn.ant.common.persistence.Page;
import com.cn.ant.common.service.BaseService;
import com.cn.ant.modules.wechat.dao.NewsTemplateMapper;
import com.cn.ant.modules.wechat.entity.NewsTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;
/**
 * 图文消息模板Service
 * @author AntDream
 * @version 2015-03-23
 */
@Component
@Transactional(readOnly = true)
public class NewsTemplateService extends BaseService {

	@Autowired
	private NewsTemplateMapper newsTemplateMapper;
	
	public NewsTemplate get(String id) {
		return newsTemplateMapper.get(id);
	}
	
	public Page<NewsTemplate> find(Page<NewsTemplate> page, Map<String,Object> param) {
        param.put("startIdx", page.getFirstResult());
        param.put("pageSize", page.getPageSize());
        page.setList(newsTemplateMapper.query(param));
        page.setCount(newsTemplateMapper.queryCount(param));
        return page;
	}

	@Transactional(readOnly = false)
	public void save(NewsTemplate newsTemplate) {
		newsTemplateMapper.insert(newsTemplate);
	}
	
	@Transactional(readOnly = false)
	public void update(NewsTemplate newsTemplate) {
		newsTemplateMapper.update(newsTemplate);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		newsTemplateMapper.delete(id);
	}
	
}
